package game;
import fields.*;

public class Gameboard {
	
	private Field[] feltliste; //declaring array with name feltliste
	public Gameboard() // Constructor gameboard
	{
	
	 feltliste     = new Field[40]; //setting size of array feltliste 
	 feltliste[0] = new Refuge(0, "Start", 200); // setting type for first place in array list attributes type and queue defines in other classes
	 feltliste[1] = new Territory  (1, "Rodovrevej", 60, 2, 10, 30, 90, 160, 250);
	 feltliste[2] = new Chance (2, "Chance1");
	 feltliste[3] = new Territory (3, "Hvidovrevej", 60, 4, 20, 60, 180, 320, 450);
	 feltliste[4] = new Tax (4, "Indkomstskat",200);
	 feltliste[5] = new Fleet (5, "Oresund", 200);
	 feltliste[6] = new Territory (6, "Roskildevej",100, 6, 30, 90, 270, 400, 550);
	 feltliste[7] = new Chance (7,"Chance2") ;
	 feltliste[8] = new Territory (8, "Valby Langgade",100, 6, 30, 90, 270, 400, 550);
	 feltliste[9] = new Territory (9, "Allegade", 120, 8, 40, 100, 300, 450, 600);
	 feltliste[10] = new Refuge (10, "Faengsel",-50);
	 feltliste[11] = new Territory (11, "Frederiksberggade",140, 10, 50, 150, 450, 625, 750);
	 feltliste[12] = new LaborCamp (12, "Tuborg", 150);
	 feltliste[13] = new Territory (13, "Bullowsvej",140, 10, 50, 150, 450, 625, 750);
	 feltliste[14] = new Territory (14, "Gammel Kongevej",160, 12, 60, 180, 500, 700, 900);
	 feltliste[15] = new Fleet (15, "DFDS",200);
	 feltliste[16] = new Territory (16, "Bernstorffsvej", 180, 14, 70, 200, 550, 700, 900);
	 feltliste[17] = new Chance (17,"Chance3");
	 feltliste[18] = new Territory (18, "Hellerupvej",180, 14, 70, 200, 550, 700, 950);
	 feltliste[19] = new Territory (19, "Strandvejen", 200, 16, 80, 220, 600, 800, 1000);
	 feltliste[20] = new Refuge (20,"Helle", 500);
	 feltliste[21] = new Territory (21, "Trianglen", 220, 18, 90, 250, 700, 875, 1050);
	 feltliste[22] = new Chance (22, "Chance4"); 
	 feltliste[23] = new Territory (23, "Osterbrogade",220, 18, 90, 250, 700, 875, 1050);
	 feltliste[24] = new Territory (24, "Gronningen", 240, 20, 100, 300, 750, 925, 1100);
	 feltliste[25] = new Fleet (25, "OS", 200);
	 feltliste[26] = new Territory (26, "Bredgade", 260, 22, 110, 330, 800, 975, 1150);
	 feltliste[27] = new Territory (27, "Kongens Nytorv", 260,22, 110, 330, 800, 975, 1150);
	 feltliste[28] = new LaborCamp (28, "Carlsberg", 150);
	 feltliste[29] = new Territory (29, "Ostergade", 280, 24, 120, 360, 850, 1025, 1200);
	 feltliste[30] = new Jail (30, "Ga i Faengsel",0);
	 feltliste[31] = new Territory (31, "AmagerTorv", 300, 26, 130, 390, 900, 1100, 1275);
	 feltliste[32] = new Territory (32, "Vimmelskaftet", 300,26, 130, 390, 900, 1100, 1275);
	 feltliste[33] = new Chance (33,"Chance5"); 
	 feltliste[34] = new Territory (34, "Nygade", 320, 28, 150, 450, 1000, 1200, 1400);
	 feltliste[35] = new Fleet (35, "Bornholm", 200);
	 feltliste[36] = new Chance (36, "Chance6");
	 feltliste[37] = new Territory (37, "Frederiksberggade", 350, 35, 175, 500, 1100, 1300, 1500);
	 feltliste[38] = new Tax (38, "Ekstraskat", 100);
	 feltliste[39] = new Territory (39, "Radhuspladsen", 400, 50, 200, 600, 1400, 1700, 2000);
	 
	}
	
	public String toString() // Method String for showing result in line
	{
		String str="";			// String with name str w/o fixed text
		for (int i=0; i<feltliste.length; i++) //loop for  where i in the beginning = 0 and until i less than feltliste length i+1
		{
			str+=feltliste[i].toString(); //str+ feltliste
			str+="\n"; //new line
		}
		return str; 		// return
	}
	 
	public Field getField(int field)	// method getfield with attribute field¨returns object Field
	{
		return feltliste[field-1];		//	return of array with amount less on 1 than field
	}
	
	public int getFieldNumberByName(String name) {		// getMethod with one parameter that shall return result in int
		for (int i=0; i<this.feltliste.length; i++) { //loop where i in the beginning = 0  and until i less than feltliste length  i+1
			String fieldName = this.feltliste[i].getName(); // String fieldname= class variable of array i position gets name
			if (fieldName.compareTo(name) == 0) { // if fieldname = 0 
				return i+1;							//return i+1
			}
		}
		return 0;									// if fieldname  not equal 0 then return 0
	}

	public int[][] getBoardStreets() { // Method getboardstreets of double array that shall return result in int 
		int[] street1 = {2,4};			// array street1 that includes numbers  2, 4
		int[] street2 = {7,9,10};
		int[] street3 = {12,14,15};
		int[] street4 = {17,19,20};
		int[] street5 = {22,24,25};
		int[] street6 = {27,28,30};
		int[] street7 = {32,33,35};
		int[] street8 = {38,40};
		int[][] streets = {street1,street2,street3,street4,street5,street6,street7,street8}; //array that includes all arrays from above
		return streets; // return value of double array
	} 
	
	public int[] getStreet(int x) {	// method 
		int[][] streets = this.getBoardStreets();
		for(int[] street:streets) {
			for(int field:street) {
				if (field == x) {
					return street;
				}
			}
		}
		return new int[0];
	}
	
	
}
	
	 
